package com.cakemallproject.mapper;

import com.cakemallproject.pojo.mapperObj.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface UsersMapper {
    @Select("select uid, username, email, phone, is_admin, create_time, update_time, status from users where status = 1")
    List<User> list();

    @Insert("insert users(username, password, email, phone) values(#{username},#{password},#{email},#{phone}) ")
    void insert(User user);

    @Select("select uid, username, email, phone, is_admin, create_time, update_time, status from users where status = 1 and (username = #{username} or email = #{email}) and password = #{password} ")
    User getByUsernameOrEmailAndPassword(User user);

    @Select("select uid, username, email, phone, is_admin, create_time, update_time, status from users where status = 1 and uid = #{uid}")
    User getByUid(Integer uid);

    @Select("select uid, username, email, phone, is_admin, create_time, update_time, status from users where status = 1 and username = #{username}")
    User getByUsername(String username);

    void delete(List<Integer> ids);

    void update(User user);
}
